/*
 * TemperatureManager.h
 *
 * Created: 3/6/2013 11:26:44 PM
 *  Author: brodzki
 */ 

#ifndef TEMPERATUREMANAGER_H_
#define TEMPERATUREMANAGER_H_

#include <stdint.h>
#include <avr/io.h>
#include "Register.h"

class ThermometerHandler
{
	Register ddr_;
	Register pin_;
	unsigned short bit_;
	
	char l_;
	char h_;
	
public:
	ThermometerHandler(volatile uint8_t *ddr, volatile uint8_t *pin, unsigned short bit) : ddr_(ddr), pin_(pin) , bit_(bit) {}
	void			start_measurement();
	void			get_result(char *);
	float			get_result();
	
private:
	void			disable_pull_up();
	void			set_ddr(bool in);

	char			get_low() { return l_; }
	char			get_high() { return h_; }
	bool			reset_pulse();
	void			send_bit(bool bit);
	bool			read_bit();
	void			send_byte(char byte);
	unsigned char	read_byte();
};

#endif /* TEMPERATUREMANAGER_H_ */